﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.Services;
using Microsoft.AspNetCore.Hosting;

namespace System.Services
{
    public class DefaultBootstrapper : IBootstrapper
    {
        private readonly IApplicationLifetime _AppLifetime;
        private IEnumerable<IProcessingServer> _Processors { get; }

        public DefaultBootstrapper(IEnumerable<IProcessingServer> processors, IApplicationLifetime appLifetime)
        {
            _Processors = processors;
            _AppLifetime = appLifetime;
        }

        public Task BootstrapAsync()
        {
            var tasks = _Processors.Select(o => Task.Run(() => o.Start()));
            return Task.WhenAll(tasks);
        }
    }
}
